package com.example.bili.adapter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.bili.R;
import com.example.bili.allbean.recommendedBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/3/10.
 */

public class recommendedAdapter extends RecyclerView.Adapter<recommendedAdapter.VHolder> {
    private Context context;
    private ArrayList<recommendedBean.ResultBean> bean;
    public recommendedAdapter(Context context, ArrayList<recommendedBean.ResultBean> recommendedbean) {
        this.context = context;
        this.bean = recommendedbean;
    }

    @Override
    public VHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_recommended_4ximg, null);
        return new VHolder(view);
    }

    @Override
    public void onBindViewHolder(VHolder holder, int position) {
        holder.title_tv.setText(bean.get(position).getHead().getTitle());
        if (position == 0) {
            holder.titleleft_img.setBackgroundResource(R.mipmap.ic_header_hot);
            holder.titleright_img.setBackgroundResource(R.mipmap.ic_header_indicator_rank);
            holder.toprit_tv.setText("排行榜");
            holder.lin.setBackgroundResource(R.color.YELLOW);
        }
        holder.recyclerView.setLayoutManager(new GridLayoutManager(context,2));
        List<recommendedBean.ResultBean.BodyBean> body = bean.get(position).getBody();
        holder.recyclerView.setAdapter(new recommended_itemrecyAdapter(context,body));
    }

    @Override
    public int getItemCount() {
        return bean.size();
    }

    public class VHolder extends RecyclerView.ViewHolder{
        ImageView titleleft_img;
        ImageView titleright_img;
        TextView title_tv;
        TextView toprit_tv;
        RecyclerView recyclerView;
        LinearLayout lin;
        public VHolder(View itemView) {
            super(itemView);
            titleleft_img = (ImageView) itemView.findViewById(R.id.d_rm_titleimg);
            titleright_img = (ImageView) itemView.findViewById(R.id.d_rm_itemtopright_img);
            title_tv = (TextView) itemView.findViewById(R.id.d_rm_title);
            toprit_tv = (TextView) itemView.findViewById(R.id.d_rm_itemtopright_tv);
            recyclerView = (RecyclerView) itemView.findViewById(R.id.d_rm_item_item);
            lin = (LinearLayout) itemView.findViewById(R.id.d_rm_itemtopright_lin);
        }
    }
}
